package com.itcam.pro01;

import java.util.function.Predicate;
import java.util.stream.Stream;

/**
 * @author : Cammy.Wu
 * Description : 
 */

public class Demo01Filter {
    public static void main(String[] args) {
//        Stream<Fruit> fruitStream = Stream.of(
//                new Fruit("草莓", "Strawberry", "浆果", "红色"),
//                new Fruit("桑葚", "Mulberry", "浆果", "紫色"),
//                new Fruit("杨梅", "Waxberry", "浆果", "红色"),
//                new Fruit("核桃", "Walnut", "坚果", "棕色"),
//                new Fruit("花生", "Peanut", "坚果", "棕色"),
//                new Fruit("蓝莓", "Blueberry", "浆果", "蓝色")
//        ).filter(f -> f.category().equals("浆果") && f.color().equals("蓝色"));
        Stream<Fruit> fruitStream = Stream.of(
                new Fruit("草莓", "Strawberry", "浆果", "红色"),
                new Fruit("桑葚", "Mulberry", "浆果", "紫色"),
                new Fruit("杨梅", "Waxberry", "浆果", "红色"),
                new Fruit("核桃", "Walnut", "坚果", "棕色"),
                new Fruit("花生", "Peanut", "坚果", "棕色"),
                new Fruit("蓝莓", "Blueberry", "浆果", "蓝色")
        ).filter(((Predicate<Fruit>) f -> f.category().equals("浆果")).and(f -> f.color().equals("蓝色")));

        fruitStream.forEach(System.out::println);
    }

}

record Fruit(String cname, String name, String category, String color) {
}
